/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2025-02-10 16:03:18
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2025-02-27 16:16:30
 * @FilePath: /vue3-admin-server/src/entities/user.entity.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import {
    Entity,
    Column,
    ManyToMany,
    JoinTable,
    OneToOne,
    JoinColumn
} from 'typeorm';

import { BaseEntity } from './base.entity';
import { RoleEntity } from './role.entity';
import { BitToBooleanConverter } from './converters';
import { DeptEntity } from './dept.entity';
import { FileEntity } from './file.entity';

@Entity({
    name: 'user'
})
export class UserEntity extends BaseEntity {
    @Column({ length: 64 })
    username: string;

    @Column({ length: 128 })
    password: string;

    @Column({ type: 'bit', transformer: BitToBooleanConverter })
    valid: boolean;

    @ManyToMany(() => RoleEntity)
    @JoinTable({
        name: 'user_role',
        joinColumn: {
            name: 'user_id',
            referencedColumnName: 'id'
        },
        inverseJoinColumn: {
            name: 'role_id',
            referencedColumnName: 'id'
        }
    })
    roles: RoleEntity[];

    @ManyToMany(() => DeptEntity)
    @JoinTable({
        name: 'user_department',
        joinColumn: {
            name: 'user_id',
            referencedColumnName: 'id'
        },
        inverseJoinColumn: {
            name: 'department_id',
            referencedColumnName: 'id'
        }
    })
    depts: DeptEntity[];

    @OneToOne(() => FileEntity)
    @JoinColumn({ name: 'avatar_id' })
    avatar?: FileEntity;

    @Column({
        type: 'int',
        name: 'avatar_id',
        comment: '头像id'
    })
    avatarId?: number;

    @Column({
        comment: '小程序openid',
        name: 'open_id',
        length: 64
    })
    openId?: string;

    @Column({
        comment: '备注',
        length: 255
    })
    remark?: string;

    @Column({
        type: 'int',
        comment: '性别:2=女,1=男,0=未知'
    })
    gender?: number;

    @Column({
        comment: '邮箱',
        length: 255
    })
    email?: string;
}
